package com.lh.web.service.impl.order;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.lh.common.entity.admin.*;
import com.lh.common.utils.PageUtils;
import com.lh.web.dao.admin.OrderMapper;
import com.lh.web.service.serviceAdmin.order.OrderLogService;
import com.lh.web.service.serviceAdmin.order.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;

/**
 * @author FH
 * @ClassName: OrderServiceImpl
 * @Description: (类作用)
 * @date: 2020-05-18 9:36
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    OrderLogService orderLogService;

    @Override
    public PageUtils queryOrderList(Map<String, Object> param, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<OrderOneList> notices = this.baseMapper.queryOrderList(param);
        return new PageUtils(notices);
    }

    @Override
    public PageUtils getOrderList(Map<String, Object> param, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<OrderList> notices = this.baseMapper.getOrderList(param);
        return new PageUtils(notices);
    }

    @Override
    public OrderOneDetail queryOrderOneDetails(Long orderId) {
        return this.baseMapper.queryOrderOneDetails(orderId);
    }

    @Override
    public OrderDetail queryOrderDetails(Long orderId) {
        OrderDetail orderDetail = this.baseMapper.queryOrderDetails(orderId);
        List<OrderShop> orderShop = this.baseMapper.queryOrderShop(orderDetail.getOrderItem());
        List<OrderLog> maps = this.baseMapper.queryOrderLog(orderId);
        orderDetail.setOrderShop(orderShop);
        orderDetail.setOrderLog(maps);
        return orderDetail;
    }

    @Override
    @Transactional
    public int updateOrderWarehouse(Long userId, Long orderId, String oldStatus, String newStatus, String remark) {
        int i = this.baseMapper.updateOrderWarehouse(orderId, newStatus);
        orderLogService.insertOrderLog(userId,orderId,oldStatus,newStatus,remark);
        return i;
    }

    @Override
    public int updateOrderWarehouse(Long userId, Long orderId, String expressName, String expressCode, String oldStatus, String newStatus, String remark) {
        int i = this.baseMapper.updateOrderDeliver(orderId, newStatus,expressName,expressCode);
        orderLogService.insertOrderLog(userId,orderId,oldStatus,newStatus,remark);
        return i;
    }
}
